package com.assistant.wechat.service.impl;

import com.assistant.wechat.mapper.MessageMapper;
import com.assistant.wechat.pojo.Message;
import com.assistant.wechat.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public int insertMessage(Message message) {
        return messageMapper.insertSelective(message);
    }

    @Override
    public List<Message> getMessageListByRoomId(Integer id) {
        Example example = new Example(Message.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("roomid",id);
        example.setOrderByClause("create_time ASC");
        return messageMapper.selectByExample(example);
    }

    @Override
    public int insertListMessage(List<Message> messages) {
        return messageMapper.saveOrderMessage(messages);
    }

}
